<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>猜数字游戏</title>

    <style>
        body {
            background-color: #f5f5f5;
            display: flex;
            justify-content: center;
            align-items: center;
            min-height: 100vh;
            background-image: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
        }

        .guess-container {
            width: 100%;
            max-width: 400px;
            background-color: white;
            border-radius: 10px;
            box-shadow: 0 15px 35px rgba(0, 0, 0, 0.1);
            overflow: hidden;
            animation: fadeIn 0.5s ease-in-out;
        }

        .guess-header {
            background-color: #ff6b6b;
            color: rgb(248, 248, 248);
            padding: 0.5rem;
            text-align: center;
        }

        .guess-conntent {
            background-color: #ffffff;
            color: rgb(229, 87, 87);
            padding: 3.5rem;
            text-align: center;
        }

        .guess-conntent h2 {
            margin-top: -3rem;
            margin-bottom: 0.5rem;
        }

        .guess-conntent input {
            margin-bottom: 0.5rem;
        }

        .info {
            margin-top: -3rem;
            margin-left: 1rem;
        }
    </style>
</head>

<body>
    <!-- html布局 -->
    <div class="guess-container">
        <div class="guess-header">
            <h1>欢迎来到猜数字游戏</h1>
        </div>

        <div class="guess-conntent">
            <h2 class="">请输入你要猜的数字</h2>
            <input type="text" id="guess_number"><br>
            <button id="button1">确认提交</button> <button id="button2">重新开始</button>
        </div>

        <div class="info">
            猜的次数：<span id="count">0</span><br>
            结果：<span id="ret"></span>
        </div>

    </div>

    <script src="jquery-3.7.1.min.js"></script>
    <script>
        // 生成随机数
        var number = Math.floor(Math.random() * 100 + 1);
        console.log(number);
        var count = 0;
        //点击按钮
        $("#button1").click(function () {
            count++;
            $("#count").text(count);

            //获取input中的数字，然后和随机数比较
            var guessnumber = $("#guess_number").val();
            if (guessnumber < number) {
                $("#ret").text("猜小了！");
                $("#ret").css("color","red")
            } else if (guessnumber > number) {
                $("#ret").text("猜大了！");
                 $("#ret").css("color","red")
            } else {
                $("#ret").text("恭喜你猜对了！");
                 $("#ret").css("color","green")
            }
        });

        $("#button2").click(function () {
            number = Math.floor(Math.random() * 100 + 1);
            $("#guess_number").val("");
            $("#count").text(0);
            $("#ret").text("");
        })
    </script>
</body>

</html>